import Vue 			from 'vue'
import util 		from '../../util'
import axios 		from 'axios'
import { Toast } 	from 'vant';
Vue.use(Toast);

export default {
	name: 'goRealName',
	data(){
		return {
			name:'',			//姓名
			IDcard:'',			//身份证号
			loading:false,		//是否提交中
			error1:'',			//输入姓名提示错误
			error2:'',			//身份证号码提示错误
		}
	},
	methods:{
		upload(){
			//提交
			this.updateDialog();
			return
			this.checkOut().then(() => {
				this.loading = true;
				this.error1 = '';
				this.error2 = '';
				let params = {
					token:this.token || window.token || util.getToken(),
					kyc_type:1,			//1:国内   2:其他地区
					name:this.name,		//姓名
					id_no:this.IDcard,	//身份证号码
					kyc_area:'china',	//地区   china  america
					kyc_certificate:'',	//证件类型
				}
				util.fetch(`${util.ajaxUrl}/user/verified`,params).then(res => {
					if(res.retCode === 0){
						Toast(this.$t('goRealName-key10'));
						setTimeout(()=>{
							this.goBack('special')
							this.loading = false;
						},1500)
					}else{
						Toast(res.retMsg || this.$t('noError'))
						setTimeout(()=>{
							this.loading = false;
						},1500)
					}
				}).catch(error => {
					this.loading = false;
					console.log(error)
				})
			}).catch(error => {

			})
		},
		checkOut(){
			return new Promise((resolve,reject) => {
				let idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X|x)$/;
				if(this.name && idcardReg.test(this.IDcard)){
					this.error1 = '';
					this.error2 = '';
					resolve()
				}else{
					reject('');
					if(!this.name){
						this.error1 = this.$t('goRealName-key11');
					}else{
						this.error1 = '';
					}
					if(!idcardReg.test(this.IDcard)){
						this.error2 = this.$t('goRealName-key12')
					}else{
						this.error2 = '';
					}
				}
			})
		},
		goBack(special){
			util.navigateBack(-1,this,special)
		},
		goOthers(){
			this.updateDialog();
			return
			//其他地区或者证件登录
			this.$router.push('/goRealName2')
		},
		blur(){
			window.scrollTo(0, 0);
		}
	},
	created() {
		util.waitSDKReady().then(token => {
			this.token = token;
		}).catch((e) => {
			console.log('获取token失败')
		})
		setTimeout(() => {
			//退出登录的时候native调用H5方法清除token缓存
			util.registerHandler('loginOutDeleteToken',res => {
				localStorage.removeItem('token');
			})
			util.callHandler('setStatusBarStyle',{
				style:'dark'
			})
		},500)
		// this.init();
    }
}